// pages/user_end/classification/classification.js
const app = getApp();
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    heightNav:null,
    bg: '#08B266',
    nindex: 0,
    banner: [
      {
      id:1,
      image_text:'https://picsum.photos/200/50?1'
    },{
      id:2,
      image_text:'https://picsum.photos/200/50?2'
    }],
    list: [
      {id:1,name:"商品"},
      {id:2,name:"肉类"},
      {id:3,name:"蔬菜"},
      {id:4,name:"水果"},
      {id:5,name:"油粮"},
      {id:2,name:"肉类"},
      {id:3,name:"蔬菜"},
      {id:4,name:"水果"},
      {id:5,name:"油粮"},
      {id:2,name:"肉类"},
      {id:3,name:"蔬菜"},
      {id:4,name:"水果"},
      {id:5,name:"油粮"}
    ],
    category:{
      id:1,
      name:"商品",
      service:[
        {
          image_text:'https://picsum.photos/60/80?1',
          pic:30,
          name:"天"
        },
        {
          image_text:'https://picsum.photos/60/80?2',
          pic:30,
          name:"地"
        },
        {
          image_text:'https://picsum.photos/60/80?3',
          pic:30,
          name:"玄"
        },
        {
          image_text:'https://picsum.photos/60/80?4',
          pic:30,
          name:"黄"
        },
        {
          image_text:'https://picsum.photos/60/80?1',
          pic:30,
          name:"天"
        },
        {
          image_text:'https://picsum.photos/60/80?2',
          pic:30,
          name:"地"
        },
        {
          image_text:'https://picsum.photos/60/80?3',
          pic:30,
          name:"玄"
        },
        {
          image_text:'https://picsum.photos/60/80?4',
          pic:30,
          name:"黄"
        },
        {
          image_text:'https://picsum.photos/60/80?1',
          pic:30,
          name:"天"
        },
        {
          image_text:'https://picsum.photos/60/80?2',
          pic:30,
          name:"地"
        },
        {
          image_text:'https://picsum.photos/60/80?3',
          pic:30,
          name:"玄"
        },
        {
          image_text:'https://picsum.photos/60/80?4',
          pic:30,
          name:"黄"
        }
      ]
    },
    keyword: ''
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    var that = this;
    let sysInfo = wx.getSystemInfoSync();
    let menuInfo = wx.getMenuButtonBoundingClientRect();
    this.setData({
      heightNav:(sysInfo.windowHeight - 90 - ((menuInfo.top - sysInfo.statusBarHeight) * 2 + menuInfo.height)) +'px'
    })
    //商品
    wx.request({
      url: 'http://www.liyangpt.com/index.php/addons/shopro/goods.goods?category_id=21&list_rows=100&page=1',
      data: {},
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
       // console.log(res.data.data.data)
        that.setData({goods: res.data.data.data });
      }
    })
   
    //分类

    wx.request({
      url: 'http://www.liyangpt.com/index.php/addons/shopro/category?id=21',
      data: {

      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        //console.log( res.data.data.children)
        that.setData({category: res.data.data.children});
      }
    })



    // this.getBanner();
    // this.getList();
    // this.getCategory();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  clickBanner(e) {
    console.log(e);
    var jump = e.currentTarget.dataset.jump;
    var type = e.currentTarget.dataset.type;
    var id = e.currentTarget.dataset.id;
    if(jump=='1'){
      if(type=='1'){
        wx.navigateTo({
          url:"../article/article?id="+id
        })
      }else if(type=='2'){
        wx.navigateTo({
          url:"../server_info/server_info?id="+id
        })						
      }
    }
  },
  getBanner() {
    var that = this;
    let param = {
      scoure: 'wxapp',
      location: 2
    }
    wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
    request.request(url.getbannerlist, param, url.REQUEST_METHOD_GET).then((res) => {
      wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
      if(res.data.code==1){
        that.setData({
          banner:res.data.data
        })
      }
    })  			
  },
  doSearch() {
    var that = this;
    wx.navigateTo({
      url: '../server_list/server_list?id=0&type=1&key=' + that.data.keyword
    })
  },
  gotoServiceInfo(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      // url: '../server_info/server_info?id=' + id
      url: '../shop_details/shop_details?id=' + id
    })
  },
  chooseNav(e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.setData({
      nindex:e.currentTarget.dataset.navindex
    })
    // this.getCategory(id);
  },
  // getList() {
  //   var that = this;
  //   let param = {
  //     scoure: 'wxapp'
  //   }
  //   request.request(url.getcategory, param, url.REQUEST_METHOD_GET).then((res) => {
  //     that.setData({
  //       list:res.data.data
  //     })
  //     if (that.data.list.length > 0) {
  //       that.getCategory(that.data.list[0].id);
  //     }
  //   })
  // },
  // getCategory(id) {
  //   var that = this;
  //   let param = {
  //     scoure: 'wxapp',
  //     id: id
  //   }
  //   wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
  //   request.request(url.getservicesecond, param, url.REQUEST_METHOD_GET).then((res) => {
  //     wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
  //     if(res.data.code==1){
  //       that.setData({
  //         category:res.data.data
  //       })
  //     }
  //   })  	
  // },
  // changekeyword(e){
  //    var key =e.detail.value;
  //    this.setData({
  //     keyword:key
  //    })
  // }
})